// 加箭头
var firstList = document.querySelectorAll(".sidebar .sidebar-list>ul>li")
var hasChildList = []
for(let i=0;i<firstList.length;i++){
	if(firstList[i].children[1]){
		let tempDom = document.createElement('div')
		tempDom.className = 'arrow'
		firstList[i].appendChild(tempDom)
		hasChildList.push(firstList[i])
	}
}






function getRotate(matrix){
    var aa=Math.round(180*Math.asin(matrix[0])/ Math.PI);
    var bb=Math.round(180*Math.acos(matrix[1])/ Math.PI);
    var cc=Math.round(180*Math.asin(matrix[2])/ Math.PI);
    var dd=Math.round(180*Math.acos(matrix[3])/ Math.PI);
    var deg=0;
    if(aa==bb||-aa==bb){
        deg=dd;
    }else if(-aa+bb==180){
        deg=180+cc;
    }else if(aa+bb==180){
        deg=360-cc||360-dd;
    }
    // return deg>=360?0:deg;
	return deg
 
}

// 点击开启子菜单
for(let i = 0;i<hasChildList.length;i++){
	hasChildList[i].children[0].onclick = function(){
		let temp = hasChildList[i].children[1]
		let height = window.getComputedStyle(temp,null).height
		if(height == '0px'){
			hasChildList[i].children[1].style.height = (40 * temp.children.length) + 'px'
		}
		else{
			hasChildList[i].children[1].style.height = '0px'
		}
		
		// 箭头旋转
		let arrow = hasChildList[i].children[hasChildList.length]
		let currentArrow = document.defaultView.getComputedStyle(arrow,null).transform.split('(')[1].split(')')[0].split(',')
		let currentDeg = getRotate(currentArrow)
		arrow.style.transform = "rotate(" + (currentDeg + 180) + "deg)"
		
		
	}
}

// 点击高亮
var activeIndex = document.getElementsByClassName('active')[0]
var listAll = document.getElementsByTagName('li')
for(let i = 0 ; i < listAll.length ; i++){
	if(!listAll[i].children[1]){
		listAll[i].children[0].onclick = function(){
			var activeDom = document.getElementsByClassName('active')[0]
			if(activeDom){
				activeDom.classList.remove('active')
			}
			listAll[i].children[0].classList.add('active')
		}
	}
}

// 滑块
var slider = document.getElementById('slider')
var sliderHeight = slider.offsetTop

var currentPos = null
var slideList = document.getElementsByClassName('sidebar-list')[0].children[0].children
for(let i = 0 ;i < slideList.length ; i++){
	slideList[i].onmouseenter = function(){
		var tempPos = slideList[i].offsetTop
		slider.style.top = tempPos + 'px'
		slider.style.height = "40px"
	}
}
var slideUl = document.getElementsByClassName('sidebar-list')[0].children[0]
slideUl.onmouseleave = function(){
	let sliderHeight = slider.offsetTop
	slider.style.top = (sliderHeight + 20) + "px"
	slider.style.height = 0
}